import 'package:flutter/material.dart';

class RefreshListPage extends StatefulWidget {
  @override
  _RefreshListPageState createState() => _RefreshListPageState();
}

class _RefreshListPageState extends State<RefreshListPage> {
  List<String> items = List.generate(20, (index) => 'Item $index');

  Future<void> _onRefresh() async {
    // 模拟网络请求
    await Future.delayed(const Duration(seconds: 2));
    setState(() {
      items = List.generate(20, (index) => 'Refreshed Item $index');
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('下拉刷新示例')),
      body: RefreshIndicator(
        onRefresh: _onRefresh,
        child: ListView.builder(
          physics: const AlwaysScrollableScrollPhysics(), // 保证可以下拉
          itemCount: items.length,
          itemBuilder: (context, index) {
            return ListTile(
              title: Text(items[index]),
            );
          },
        ),
      ),
    );
  }
}